package com.tcsl.mylibrary;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import java.util.ArrayList;
import java.util.List;

import cn.com.tcsl.canyin7.pay.utils.FFResult;
import cn.com.tcsl.canyin7.pay.utils.PosHelper;

/**
 * 描述:飞凡支付
 * <p/>作者：wjx
 * <p/>创建时间: 2017/5/26 16:44
 */
public class PayFeiFan extends TcslPay {
    private static final int PAY_FEI = 0x6eff;

    public PayFeiFan(Context context) {
        super(context);
    }

    @Override
    protected void pay(Float money, String orderNo, String merchantNo) {
        List<PosHelper.Product> products = new ArrayList<PosHelper.Product>();
        boolean pay = PosHelper.pay(mActivity, orderNo + "_" + timeStamp,
                "linqingxuan001", Math.round((Double.valueOf(money) * 100)),
                10, products, PAY_FEI);
        if (!pay) {
            mListener.payError("启动支付失败");
        }
    }

    @Override
    public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PAY_FEI) {
            if (resultCode == Activity.RESULT_OK) {
                FFResult.PayResult payResult = PosHelper.getPayResult(data);
                if (payResult.mResult == 0) {
                    mListener.paySuccess("支付成功", payResult.mPayOrderNo);
                } else if (payResult.mResult == 1) {
                    mListener.payError("支付失败");
                } else {
                    mListener.payError("支付关闭");
                }
            } else if (resultCode == Activity.RESULT_CANCELED) {
                mListener.payError("支付取消");
            }
            return true;
        } else {
            return false;
        }
    }
}
